local skel = fk.CreateSkill{
  name = "tea__yinhe",
}
--local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["tea__yinhe"] = "隐壑",
  [":tea__yinhe"] = "结束阶段，你可以将手牌数调整至不为场上最多且不与其他角色相同。手牌数与你不同的角色使用【杀】时，不能指定你为目标。",
  ["#tea__yinhe-discard"] = "隐壑：你需要弃置 %arg 张手牌",
}
---@type TrigSkelSpec<DamageTrigFunc>
local yinhe = {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player == target and player:hasSkill(skel.name) and player.phase == Player.Finish
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, { skill_name = skel.name }) then
      local choices = {}
      local card_counts = {}
      for _, p in ipairs(player.room:getAlivePlayers()) do
         table.insertIfNeed(card_counts, #p:getCardIds("h")) 
      end
      table.sort(card_counts, function (a, b)
        return a > b
      end)
      if card_counts[1] > 0 then
        for i = 0, card_counts[1] do
          if not table.contains(card_counts, i) then
            table.insert(choices, tostring(i))
          end
        end
        if #choices > 0 then
          table.insert(choices, 1, "Cancel")
          local choice = player.room:askToChoice(player, {
            choices = choices,
            skill_name = skel.name,
          })
          if choice ~= "Cancel" and choice ~= "" then
            event:setCostData(self, { num = tonumber(choice) })
            return true
          end
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local num = event:getCostData(self).num ---@type integer
    local n = #player:getCardIds("h") - num
    if n < 0 then
      player:drawCards(- n, skel.name)
    elseif n > 0 then
      room:askToDiscard(player, {
        min_num = n,
        max_num = n,
        skill_name = skel.name,
        cancelable = false,
        prompt = "#tea__yinhe-discard:::" .. n
      })
    end
  end
}
---@type ProhibitSpec
local yinhe_prohibit = {
  is_prohibited = function (self, from, to, card)
    return card.trueName == "slash" and to:hasSkill(skel.name) and #from:getCardIds("h") ~= #to:getCardIds("h")
  end
}
skel:addEffect(fk.EventPhaseStart, yinhe)
skel:addEffect("prohibit", yinhe_prohibit)
-- Fk.generals["mouxusheng"]:addSkill(skel.name)
return skel